/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package jcode.hibernate;

import jcode.hibernate.model.Employee;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

/**
 *
 * @author maddog
 */
public class JcodeHibernate {
    
    private static SessionFactory sessionFactory = null;

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Session session = null;
        try {
            try {
                sessionFactory = PersonFactory.getSessionFactory();
                session = sessionFactory.openSession();
 
                System.out.println("Insertando registro");
                Transaction tx = session.beginTransaction();
                //Creando un Objeto
                Employee employe = new Employee();
                employe.setFirstname("John");
                employe.setLastname("Castillo");
                //Guardando
                session.save(employe);
                tx.commit();
                System.out.println("Finalizado...");
            } catch (Exception e) {
                System.out.println(e.getMessage());
            }
        } finally {
            session.close();
        }
    }
    
}
